package com.cooper.controllers.seller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.cooper.constants.AppConstants;
import com.cooper.constants.ResourceConstants;
import com.cooper.controllers.Controller;
import com.cooper.core.JsonResult;
import com.cooper.pagination.PageInfo;
import com.cooper.pagination.PageResult;
import com.cooper.service.item.ItemInfoService;
import com.cooper.service.seller.DesignerService;
import com.cooper.vo.DesignerSearchVo;
import com.cooper.vo.DesignerVo;
import com.cooper.vo.ItemInfoVo;
import com.cooper.vo.ItemSearchVo;

import net.paoding.rose.web.Invocation;
import net.paoding.rose.web.annotation.Param;
import net.paoding.rose.web.annotation.rest.Get;
import net.paoding.rose.web.annotation.rest.Post;

public class ShopsController extends Controller {
	
	@Autowired
	private DesignerService designerService;
	
	@Autowired
	private ItemInfoService itemInfoService;

	@Get @Post
	public String execute(Invocation inv, DesignerSearchVo searchVo, PageInfo pageInfo) throws Exception{
		searchVo.setSellerType(ResourceConstants.SellerType.PERSONAL);
		pageInfo.setPageSize(ITEMS_PER_PAGE);
		PageResult<DesignerVo> pageResult = this.designerService.queryForList(searchVo, pageInfo);
		inv.addModel("entityList", pageResult.getResult());
		inv.addModel(AppConstants.pageInfo, pageInfo);
		inv.addModel("searchVo", searchVo);
		inv.addModel("keyword", searchVo.getKeyword());
		inv.addModel("pageTitle", "SHOPS");
		return "Shops";
	}
	
	@Get("getLastItems")
	public Object getLastItems(Invocation inv, @Param("sellerId") long sellerId, PageInfo pageInfo) throws Exception {
		JsonResult json = new JsonResult();
		pageInfo.setPageSize(4);
		List<ItemInfoVo> itemList = this.itemInfoService.queryItemInfoList(sellerId, new ItemSearchVo() , pageInfo);
		json.setSuccess(true);
		json.put("itemList", itemList);
		return json;
	}
}
